/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.mts.client.core.modal;

import com.google.common.collect.Lists;
import com.intelligent.mts.core.dto.HistoryDto;
import javax.swing.table.AbstractTableModel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by cherry on 2016/7/22.
 */
public class HistoryModal extends AbstractTableModel {

    private String columns[];

    private List<HistoryDto> data;

    public HistoryModal (String columns[]) {
        this.columns = columns;
    }

    @Override
    public int getRowCount() {
        if (data == null) {
            return 0;
        }
        else {
            return data.size();
        }
    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }

    @Override
    public String getColumnName(int column) {
        return columns[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        HistoryDto historyDto = data.get(rowIndex);
        if (columnIndex == 0) {
            return historyDto.getStationId();
        } else if (columnIndex == 1) {
            return historyDto.getStationName();
        } else if (columnIndex == 2) {
            return historyDto.getPcba();
        } else if (columnIndex == 3) {
            return historyDto.getHs();
        } else if (columnIndex == 4) {
            return historyDto.getHou();
        } else if (columnIndex == 5) {
            Date date = historyDto.getCreateTime();
            SimpleDateFormat sdf= new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
            String time = sdf.format(date);
            return time;
        }
        return historyDto.getResult();
    }

    public void setData(List<HistoryDto> data) {
        if (data == null) {
            data = Lists.newArrayList();
        }
        this.data = data;
        fireTableDataChanged();
    }
}
